<template>
  <div id="app">
    <vue-loading v-show="showload" type="bubbles" color="#d9544e" :size="{ width: '50px', height: '50px' }"></vue-loading>
    <router-view :allflag="allflag" v-show="showcontent" v-on:nexttoo="fresh" :orderdata=orderdata></router-view>
  </div>
</template>

<script>
	
	
import qs from 'qs'
import axios from 'axios'
import vueLoading from 'vue-loading-template'
export default {
  name: 'app',
  data(){
    return {
      orderdata:[],
      page:1,
      showload:true,
      showcontent:false,
      lastdata:{},
      allflag:false
    }
  },
  mounted:function(){
    var _this=this
    axios.post(sessionStorage.baseurl+"/a/phone/getOrderData",qs.stringify({openid:sessionStorage.openid,sellerid:sessionStorage.sellerid,pageNo:_this.page,pageSize:10,token:sessionStorage.token}))
			.then(function(res){
				if(res.data.code==1){
					_this.showload=!_this.showload
          _this.showcontent=!_this.showcontent
				_this.$nextTick(function(){
					console.log(res.data)
					_this.orderdata=res.data.data
					_this.lastdata=res.data.data
					console.log(res.data.data)
				})
				}
				else{
					alert(res.data.msg)
				}
			})
			.catch(function(error){
				alert(error)
			})
  },
  methods:{
  	fresh:function(data){
  		this.allflag=false
  		var _this=this
  		_this.page++
    axios.post(sessionStorage.baseurl+"/a/phone/getOrderData",qs.stringify({openid:sessionStorage.openid,sellerid:sessionStorage.sellerid,pageNo:_this.page,pageSize:10,token:sessionStorage.token}))
			.then(function(res){
				if(res.data.code==1){
					console.log(res.data.data)
					if(res.data.data[0].createDate==_this.lastdata[0].createDate){
						alert("已加载全部数据")
						_this.orderdata=_this.orderdata
						_this.allflag=true
						return
					}
					_this.lastdata=res.data.data
				_this.$nextTick(function(){
					_this.orderdata=_this.orderdata.concat(res.data.data)
					
				})
				}
				else{
					alert(res.data.msg)
				}
			})
			.catch(function(error){
				alert(error)
			})
  	}
  },
  components:{
    vueLoading
  }
}
</script>

<style  lang="stylus" rel="stylesheet/stylus">
	 @import 'common/stylus/index'
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  height 100%
}
</style>
